<!DOCTYPE html>
<html>
<head>
<!-- <meta charset="utf-8">
<title>Insert title here</title> -->
</head>
   <meta charset="utf-8">
  <title>文库图书管理</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<script src="../../layuilay/layui.js" charset="utf-8"></script>
	<script src="../../js/jquery-3.4.1.min.js" charset="utf-8"></script>
	<link rel="stylesheet" href="../../layuilay/css/layui.css"  media="all">
<body>
    <!-- 检索框开始———————————————————— -->
		<div class="layuimini-container">
			<div class="layuimini-main">
				<fieldset class="layui-elem-field layuimini-search">
					<legend>搜索信息</legend>
					<div style="margin: 10px 10px 10px 10px">
						<form class="layui-form layui-form-pane" action="">
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">书号</label>
									<div class="layui-input-inline">
										<input type="text" id="r_id" autocomplete="off"
											class="layui-input">
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">书名</label>
									<div class="layui-input-inline">
										<input type="text" id="r_name"  autocomplete="off"
											class="layui-input">
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">价格</label>
									<div class="layui-input-inline">
											<input type="text" id="r_price"  autocomplete="off"
											class="layui-input">
									</div>
								</div>
							
								
								<div class="layui-inline">
									<button type="button" class="layui-btn layui-btn-normal layui-btn-radius" onclick="searchBtn()"><i class="layui-icon">&#xe615</i></button>
								</div>
							</div>
						</form>
					</div>
				</fieldset>
	
			<!-- 检索框结束 -->
     <table id="demo" lay-filter="test"></table>
      <script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
</script>
<div id = "tb"  style="display:none">
<button type="button" id="importData" class="layui-btn layui-btn-primary layui-btn-radius">导入</button>
<button type="button" onclick="exportData()"  class="layui-btn layui-btn-primary layui-btn-radius">导出</button>
    <button type="button" onclick="addbtn()" class="layui-btn">
  <i class="layui-icon">&#xe608;</i> 添加
</button>
</div> 
</div>
</div>
<script>
   
function loadcate(){
  	 $.post("/selAllProductCate",{},function(res){
  		/*  -注-用来清理，下拉框循环导致的问题 */

  		 for(var i=0;i<res.length;i++){
  			 $("#classId").append("<option value='"+res[i].id+"'>"+res[i].classId+"</option>");
 			 

			}
  	 },"json");
   }

layui.use('jquery',function(){
	var $=layui.$;
	$(function(){
		searchBtn();
		    
		})
})
  /* layui.use('jquery',function(){
	  var $=layui.$;
	  
	  }) */
		var tableObj;
	function searchBtn(){
		  var r_id=$("#r_id").val();//
		   var r_name=$("#r_name").val();
		   var r_price=$("#r_price").val();
		 
	layui.use(['table','upload','laydate'], function(){
	  var table = layui.table;
	  var upload = layui.upload;
	  var laydate=layui.laydate;
	  var form = layui.form;
	//日期时控件
	  laydate.render({
		    elem: '#pubDate'
		    ,type: 'datetime'
		  });
	  
	  tableObj= table.render({
	    elem: '#demo'
	    ,toolbar:"#tb"
	    ,url:'../../queryAll'
	        ,where:{
	        	isbn:r_id,
				name:r_name,
				price:r_price    
	            }
	    ,cols: [[
	    	{field:'bookId', width:80, title: '图书ID', sort: true}
		      ,{field:'name', width:80, title: '书名'}
		      ,{field:'author', width:80, title: '作者', sort: true}
		      ,{field:'publish', width:80, title: '出版社'}
		      ,{field:'isbn', title: '书号'} 	      
		      ,{field:'introduction', title: '简介', sort: true}
		      ,{field:'language', title: '语言', sort: true}
			  ,{field:'price', title: '价格', sort: true}
		      ,{field:'pubDate', title: '发布日期', sort: true}
		      ,{field:'classId', title: '图书类别',templet:showStatus}
		      ,{field:'number', width:137, title: '数量', sort: true}
		      ,{field:'lendnum', title: '被借阅次数', sort: true}
		      ,{field:'position', title: '位置', sort: true}
		      ,{fixed: 'right', width: 165, align:'center', toolbar: '#barDemo'}
	    ]]
	  ,page: true
	  });
	  //导入
	  upload.render({
	   elem: '#importData'
	   ,url: '../../importDataurl' //改成您自己的上传接口
	   ,accept: 'file' //普通文件
	 ,exts: 'xls|xlsx' //只允许上传压缩文件
	 ,method:"post"
	   ,done: function(res){
	     if(res.success){
	   	  layer.msg(res.message);
	   	  tableObj.reload();
	     }
	   }
	 })
	});

	}





//导出
function exportData(){
	layui.use("jquery",function(){
		var $= layui.$;
		$.ajax({
			url:"../../exportData",
			data:{},
			dataType:"json",
			type:"post",
			success:function(res){
				if(res.success){
					layer.msg(res.message);
				}
			}
		})
	})
} 




//点击添加按钮
var index;
function addbtn(){
	  layui.use(["layer","jquery"],function(){
		var layer = layui.layer;
		var $= layui.$;
		index = layer.open({
			type:1
			,title:"图书添加",
			content:$("#addusewin")
			,area:["500px","650px"]
	})
	})	
}

//点击添加保存
	function addbook(){
		layui.use(["jquery","layer"],function(){
			var $= layui.$;
			var layer=layui.layer;
			
			
			var name=$("#name").val();
			var author = $("#author").val();
			var publish=$("#publish").val();
			var isbn=$("#isbn").val();
			var introduction=$("#introduction").val();
			var language=$("#language").val();
			var price=$("#price").val();
			
			var pubDate=$("#pubDate").val();
			var classId=$("#classId").val();
			 // var classId=$("#classId option:selected").val();
			var number=$("#number").val();
			var lendnum=$("#lendnum").val();
			var position=$("#position").val();
			if(name==""){
                         layer.msg("书名不能为空")
				}else if(author=="" ){
					 layer.msg("作者不能为空")
					}else if(publish=="" ){
					 layer.msg("出版社不能为空")
					}else if(isbn==""){
					 layer.msg("书号不能为空")
					}else if(introduction==""){
					 layer.msg("简介不能为空")
					}else if(language==""){
					 layer.msg("语言不能为空")
					}else if(price==""){
					 layer.msg("价格不能为空")
					}else if(pubDate==""){
					 layer.msg("发布日期不能为空")
					}else if(classId==0){
					 layer.msg("图书类别编号不能为空")
					}else if(number==0){
					 layer.msg("数量不能为空")
					}else if(lendnum==0){
					 layer.msg("被借阅次数不能为空")
					}else if(position==""){
					 layer.msg("位置不能为空")
					}else {
						$.post("/insertbook",{
					  		name:name,
					  		author:author,
					  		publish:publish,
					  		isbn:isbn,
					  		introduction:introduction,
					  		language:language,
					  		price:price,
					  		pubDate:pubDate,
					  		classId:classId,
					  		number:number,
					  		lendnum:lendnum,
					  		position:position
					  	},function(res){
					  		if(res.success){
					  			layer.msg(res.message);
					  			layer.close(index);
					  			tableObj.reload();
					  		}
					  	},"json");
						}
		  
			
				
			})
		
	}

	//点击修改保存
	function updatebtn(){
		layui.use("jquery",function(){
			var $= layui.$;
			var ubookId=$("#upbookId").val();
			var uname=$("#upname").val();
			var uauthor = $("#upauthor").val();
			var upublish=$("#uppublish").val();
			var uisbn=$("#upisbn").val();
			var uintroduction=$("#upintroduction").val();
			var ulanguage=$("#uplanguage").val();
			var uprice=$("#upprice").val();
			var upubDate=$("#uppubDate").val();
			var uclassId=$("#upclassId").val();
			var unumber=$("#upnumber").val();
			var ulendnum=$("#uplendnum").val();
			var uposition=$("#upposition").val();
			if(uname==""){
				layer.msg("书名不能为空")
				}else if(uauthor=="" ){
					 layer.msg("作者不能为空")
				}else if(upublish=="" ){
				 layer.msg("出版社不能为空")
				}else if(uisbn==""){
				 layer.msg("书号不能为空")
				}else if(uintroduction==""){
				 layer.msg("简介不能为空")
				}else if(ulanguage==""){
				 layer.msg("语言不能为空")
				}else if(uprice==""){
				 layer.msg("价格不能为空")
				}else if(upubDate==""){
				 layer.msg("发布日期不能为空")
				}else if(uclassId==0){
				 layer.msg("图书类别编号不能为空")
				/* }else if(unumber==0){
				 layer.msg("数量不能为空") */
				}/* else if(ulendnum==0){
				 layer.msg("被借阅次数不能为空")
				} */else if(uposition==""){
				 layer.msg("位置不能为空")
				}else{
					$.post("/update",{
				  		bookId:ubookId,
				  		name:uname,
				  		author:uauthor,
				  		publish:upublish,
				  		isbn:uisbn,
				  		introduction:uintroduction,
				  		language:ulanguage,
				  		price:uprice,
				  		pubDate:upubDate,
				  		classId:uclassId,
				  		number:unumber,
				  		lendnum:ulendnum,
				  		position:uposition
				  	},function(res){
				  		if(res.success){
				  			layer.msg(res.message);
				  			layer.close(uindex);
				  			tableObj.reload();
				  		}
				  	},"json");
					
					}
		  
				
			})
		
	}
layui.use(['table','form','jquery'],function(){
	var table=layui.table;
	var form=layui.form;   
	  var $=layui.$; 
	table.on('tool(test)',function(obj){
		 var data = obj.data;
		if(obj.event === 'edit'){
	   	 
	    	form.val("fm",data);
			   uindex = layer.open({
			    	 type:1
			    	 ,title:"修改"
			    	 ,content:$("#updatewin")
			    	 ,area:['600px','500px']
			     })
	     }
	})
})

function showStatus(data) {
    var status = data.classId;
    var result;
    if (status == 1) {
        result = '<a class="" >马克思主义</a>';
    }
    if (status == 2) {
        result = '<a class="" >哲学</a>';
    }
    if (status == 3) {
        result = '<a class="" >社会科学总论</a>';
    }
    if (status == 4) {
        result = '<a class="" >政治法律</a>';
    }
    if (status == 5) {
        result = '<a class="" >军事</a>';
    }
    if (status == 6) {
        result = '<a class="" >经济</a>';
    }
    if (status == 24) {
        result = '<a class="" >123</a>';
    }
    return result;
}	

</script>
 <!--添加窗体  -->
<div  id="addusewin" style="display:none">

<form class="layui-form" action="">
		         <div class="layui-form-item">
			    <label class="layui-form-label">书名：</label>
			    <div class="layui-input-inline">
			      <input type="text"  id="name" name="name" placeholder="" autocomplete="off" class="layui-input">
			    </div>
			  </div>
		    <div class="layui-form-item">
		    <label class="layui-form-label">作者</label>
		    <div class="layui-input-inline" >
		      <input type="text" id="author"  name="author" lay-verify="" autocomplete="off" placeholder="" class="layui-input">
		    </div>
		  </div>
		   <div class="layui-form-item">
			    <label class="layui-form-label">出版社：</label>
			    <div class="layui-input-inline">
			      <input type="text"  id="publish" name="publish" placeholder="" autocomplete="off" class="layui-input">
			    </div>
			  </div>
			   <div class="layui-form-item">
			    <label class="layui-form-label">书号：</label>
			    <div class="layui-input-inline">
			      <input type="text"  id="isbn" name="isbn" placeholder="" autocomplete="off" class="layui-input">
			    </div>
			  </div>
			   <div class="layui-form-item">
			    <label class="layui-form-label">简介：</label>
			    <div class="layui-input-inline">
			      <input type="text"  id="introduction" name="introduction" placeholder="" autocomplete="off" class="layui-input">
			    </div>
			  </div>
			   <div class="layui-form-item">
			    <label class="layui-form-label">语言：</label>
			    <div class="layui-input-inline">
			      <input type="text"  id="language" name="language" placeholder="" autocomplete="off" class="layui-input">
			    </div>
			  </div>
			   <div class="layui-form-item">
			    <label class="layui-form-label">价格：</label>
			    <div class="layui-input-inline">
			      <input type="text"  id="price" name="price" placeholder="" autocomplete="off" class="layui-input">
			    </div>
			  </div>
			   <div class="layui-form-item">
			    <label class="layui-form-label">发布日期：</label>
			    <div class="layui-input-inline">
			     <!--  <input type="text"  id="pubDate" name="pubDate" placeholder="" autocomplete="off" class="layui-input"> -->
			           <input type="text" id="pubDate" name="pubDate"
						placeholder="yyyy-MM-dd-HH-dd-ss" lay-verify="date"
						class="layui-input">
			     </div>
			  </div>
			   <div class="layui-form-item">
			    <label class="layui-form-label">图书类别编号：</label>
			    <div class="layui-input-inline">
 			     <input type="text"  id="classId" name="classId" placeholder="" autocomplete="off" class="layui-input"> 
 			            <!-- <div class="layui-input-inline">
											<select id="classId" onfocus="selCla()">
												<option value="">请选择</option>
											</select>
									</div> -->
 			    </div>
			  </div>
			   <div class="layui-form-item">
			    <label class="layui-form-label">数量：</label>
			    <div class="layui-input-inline">
			      <input type="text"  id="number" name="number" placeholder="" autocomplete="off" class="layui-input">
			    </div>
			  </div>
			   <div class="layui-form-item">
			    <label class="layui-form-label">被借阅次数：</label>
			    <div class="layui-input-inline">
			      <input type="text"  id="lendnum" name="lendnum" placeholder="" autocomplete="off" class="layui-input">
			    </div>
			  </div>
			   <div class="layui-form-item">
			    <label class="layui-form-label">位置：</label>
			    <div class="layui-input-inline">
			      <input type="text"  id="position" name="position" placeholder="" autocomplete="off" class="layui-input">
			    </div>
			  </div>
			  
		  <div class="layui-form-item">
		    <div class="layui-input-block">
		    <button type="button" class="layui-btn layui-btn-normal layui-btn-radius" onclick="addbook()">立刻添加</button>
		     
		      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
		    </div>
		  </div>
		  </form>
</div>

  <!--修改窗体  -->
<div  id="updatewin" style="display:none">

<form class="layui-form" action="" lay-filter="fm">
    
              <div class="layui-form-item" style="display: none;">
			    <label class="layui-form-label">图书ID：</label>
			    <div class="layui-input-inline">
			      <input type="text" readonly="readonly" id="upbookId" name="bookId" placeholder="" autocomplete="off" class="layui-input">
			    </div>
			  </div>
		     <div class="layui-form-item">
			    <label class="layui-form-label">书名：</label>
			    <div class="layui-input-inline">
			      <input type="text"  id="upname" name="name" placeholder="" autocomplete="off" class="layui-input">
			    </div>
			  </div>
		    <div class="layui-form-item">
		    <label class="layui-form-label">作者</label>
		    <div class="layui-input-inline" >
		      <input type="text" id="upauthor"  name="author" lay-verify="" autocomplete="off" placeholder="" class="layui-input">
		    </div>
		  </div>
		   <div class="layui-form-item">
			    <label class="layui-form-label">出版社：</label>
			    <div class="layui-input-inline">
			      <input type="text"  id="uppublish" name="publish" placeholder="" autocomplete="off" class="layui-input">
			    </div>
			  </div>
			   <div class="layui-form-item">
			    <label class="layui-form-label">书号：</label>
			    <div class="layui-input-inline">
			      <input type="text"  id="upisbn" name="isbn" placeholder="" autocomplete="off" class="layui-input">
			    </div>
			  </div>
			   <div class="layui-form-item">
			    <label class="layui-form-label">简介：</label>
			    <div class="layui-input-inline">
			      <input type="text"  id="upintroduction" name="introduction" placeholder="" autocomplete="off" class="layui-input">
			    </div>
			  </div>
			   <div class="layui-form-item">
			    <label class="layui-form-label">语言：</label>
			    <div class="layui-input-inline">
			      <input type="text"  id="uplanguage" name="language" placeholder="" autocomplete="off" class="layui-input">
			    </div>
			  </div>
			   <div class="layui-form-item">
			    <label class="layui-form-label">价格：</label>
			    <div class="layui-input-inline">
			      <input type="text"  id="upprice" name="price" placeholder="" autocomplete="off" class="layui-input">
			    </div>
			  </div>
			   <div class="layui-form-item">
			    <label class="layui-form-label">发布日期：</label>
			    <div class="layui-input-inline">
			      <input type="text"  id="uppubDate" name="pubDate" placeholder="" autocomplete="off" class="layui-input">
			    </div>
			  </div>
			   <div class="layui-form-item">
			    <label class="layui-form-label">图书类别编号：</label>
			    <div class="layui-input-inline">
			    <input type="text"  id="upclassId" name="classId" placeholder="" autocomplete="off" class="layui-input"> 
			       
			    </div>
			  </div>
			   <div class="layui-form-item">
			    <label class="layui-form-label">数量：</label>
			    <div class="layui-input-inline">
			      <input type="text"  id="upnumber" name="number" placeholder="" autocomplete="off" class="layui-input">
			    </div>
			  </div>
			   <div class="layui-form-item" >
			    <label class="layui-form-label">被借阅次数：</label>
			    <div class="layui-input-inline">
			      <input type="text" disabled="disabled" id="uplendnum" name="lendnum" placeholder="" autocomplete="off" class="layui-input">
			    </div>
			  </div>
			   <div class="layui-form-item">
			    <label class="layui-form-label 	">位置：</label>
			    <div class="layui-input-inline">
			      <input type="text"  id="upposition" name="position" placeholder="" autocomplete="off" class="layui-input">
			    </div>
			  </div>
			   <div class="layui-form-item">
		    <div class="layui-input-block">
		    <button type="button" class="layui-btn layui-btn-normal layui-btn-radius" onclick="updatebtn()">立刻修改</button>
		     
		      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
		    </div>
		  </div>
		  </form>
</div>
                  
</body>
</html>